<template>  
  <div class="search-history">
    <van-cell title="搜索历史">
      <template v-if="isDeleteShow">
        <span @click="$emit('clearhistory')">全部删除</span>
        &nbsp;&nbsp;
        <span @click="isDeleteShow = false">完成</span>
      </template>
      
      <van-icon 
        v-else 
        name="delete" 
        @click="isDeleteShow = !isDeleteShow"
      />
    </van-cell>
    <van-cell
      v-for="(item, index) in searchHistories"
      :key="index"
      :title="item"
      @click="handlerHistory(item, index)"
    >
      <van-icon 
        name="close"
        v-show="isDeleteShow"
      />
    </van-cell>
  </div>
</template>

<script>
export default {
  props: ['searchHistories'],
  data() {
    return {
      isDeleteShow: false
    }
  },
  methods: {
    handlerHistory(item, i) {
      if(this.isDeleteShow) {
        this.searchHistories.splice(i, 1)
      } else {
        this.$emit('go-resut', item)
      }
    }
  }
}
</script>

<style>

</style>